package com.zsguan.z.meixi;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zsguan.z.slogger4andr.ZLogger;

import java.util.Random;

/**
 * Created by Administrator on 2015/9/17.
 * Text View Fragment
 */
public class FragmentTextView extends Fragment {

    private TextView mTextView;
    private String mName;

    public FragmentTextView() {
        mName = "TEST";
    }

    public FragmentTextView(String name) {
        this.mName = name;
        setLeftName("VpiFragment()");
    }

    public String getName() {
        return mName;
    }

    @Override
    public void setArguments(Bundle args) {
        super.setArguments(args);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        setLeftName("onAttach");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setLeftName("onCreate");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        setLeftName("onCreateView");
        Random random = new Random(255);

        TextView tv = new TextView(getActivity());
        tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        tv.setTextColor(getResources().getColor(R.color.black));
//        tv.setBackgroundColor(getResources().getColor(R.color.blue1));
        tv.setBackgroundColor(Color.argb(255, random.nextInt(), random.nextInt(), random.nextInt()));
        tv.setText(mName);
        return tv;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mTextView = (TextView) view;

        setLeftName("onViewCreated");
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setLeftName("onActivityCreated");
    }

    @Override
    public void onStart() {
        setLeftName("onStart");
        super.onStart();
    }

    @Override
    public void onResume() {
        setLeftName("onResume");
        super.onResume();
    }

    @Override
    public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
        super.onViewStateRestored(savedInstanceState);
        setLeftName("onViewStateRestored");
    }

    @Override
    public void onPause() {
        setLeftName("onPause");
        super.onPause();
    }

    @Override
    public void onStop() {
        setLeftName("onStop");
        super.onStop();
    }

    @Override
    public void onDestroyView() {
        setLeftName("onDestroyView");
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        setLeftName("onDestroy");
        super.onDestroy();
    }

    @Override
    public void onDetach() {
        setLeftName("onDetach");
        super.onDetach();
    }

    void setLeftName(String left) {
        ZLogger.i(mName + ": " + left);
        if (null != mTextView) {
            mTextView.append(mName);
            mTextView.append(": ");
            mTextView.append(left);
            mTextView.append("\r\n");
        }
    }

}
